function MyCalendar(funHandler1,funHandler2,funHandler3,calObjName){
	  this.callAjax1 = funHandler1;
	  this.callAjax2 = funHandler2;
	  this.callAjax3 = funHandler3;
	  this.objectName = calObjName;

	  this.YEAR = "\u5e74";  //year flag
	  this.MONTH = "\u6708"; //month flag
	  this.header = ["\u65e5","\u4e00","\u4e8c","\u4e09","\u56db","\u4e94","\u516d"];

	  this.cur_days;//current date days
	  this.cur_style;//the style of current day
	  this.isSelected =false;//the index of previous current element;
};
/*initial every day*/
MyCalendar.prototype.GetDataStr=function(y,m){

    var DayArray=[];

    for(var i=0;i<42;i++) DayArray[i]="&nbsp;";
    for(var i=0;i<new Date(y,m+1,0).getDate();i++) DayArray[i+new Date(y,m,1).getDay()]=i+1;
	this.cur_days = DayArray;
    return DayArray;
};

MyCalendar.prototype.GetTableStr=function(y,m){

	var sDays = [];
	try{
		sDays = this.callAjax2(y,m);
	}catch(err){
	    alert("---err:"+err);
	}
	if(undefined == sDays){
		sDays = [];
	}

    var DStr="<table width='95%' border='0' cellpadding='0' cellspacing='0'>";
     DStr += "		<tr>";
	 DStr += "         <td colspan='7' valign='top'>";
     DStr += "             <table width='100%' border='0' cellpadding='0' cellspacing='0' class='calendar_month'>";
	 DStr += "                 <tr>";
     DStr += "                    <td align='right'><img src='images/ico_calendar_pre.gif' onclick='"+this.objectName+".JumpToRun(\"b\")'/></td>";
     DStr += "                    <td width='60' class='calendar_datafont' align='center' id='YearTD' onclick='"+this.objectName+".WriteSelect(this,this.innerText.split(\" \")[0],\"y\",false)'>"+y+" "+this.YEAR+"</td>";
     DStr += "                    <td width='40' class='calendar_datafont' align='center' id='MonthTD' onclick='"+this.objectName+".WriteSelect(this,this.innerText.split(\" \")[0],\"m\",false)'>"+(m+1)+" "+this.MONTH +"</td>";
     DStr += "                    <td align='left'><img src='images/ico_calendar_next.gif' onclick='"+this.objectName+".JumpToRun(\"n\")'/></td>";
     DStr += "                 </tr>";
	 DStr += "              </table>";
     DStr += "          </td>";
	 DStr += "       </tr>";
     DStr += "       <tr class='calendar_date_header' >";

     for(var i=0;i<7;i++){
	     	if(i != 0 && i !=6){
	     		 DStr+="<td width='20' height='21'><strong>"+this.header[i]+"</strong></td>";
	     	}else{
	     		  DStr+="<td width = '20' height='21' class='font_orange'><strong>"+this.header[i]+"</strong></td>";
	     	}
     }



     DStr += "       </tr>";

    var days = this.GetDataStr(y,m);

    for(var i=0;i<6;i++){
    		DStr+="  <tr class='calendar_date'>";
    		for(var j=0;j<7;j++){
        		var CS = " class=''";
				var curId= "TD" + (i*7+j);
        		var curName = "TD";
        		if(new Date().getDate()==days[i*7+j]){
        			 CS = " class='calendar_current'";
          			 curName = "CURCOL";
					 for(t=0;t<sDays.length;t++){
						if(sDays[t] == days[i*7+j]){
							 this.isSelected=true;
					}}
        	    }else{
					for(t=0;t<sDays.length;t++){
						if(sDays[t] == days[i*7+j]){
							 CS = " class='calendar_msg'";
						}
					}
				}
					DStr+="<span id='"+curId+"'> <td height='24' id='"+curName+"'"+CS+"   onclick='"+this.objectName+".changeStyle(this,YearTD.innerText.split(\" \")[0],MonthTD.innerText.split(\" \")[0],this.innerText)' onDblClick='"+this.objectName+".onDbClickFunc(this,YearTD.innerText.split(\" \")[0],MonthTD.innerText.split(\" \")[0],this.innerText)' onmouseover='"+this.objectName+".onMouseOver(this);' onmouseout='"+this.objectName+".onMouseOut(this)'>"+ this.GetDataStr(y,m)[i*7+j]+"</td></span>\n";
    		}
    		DStr+="</tr>\n";
    }
    DStr+="</table>";

    //clipboardData.setData("text", DStr);
    //alert(DStr);

	this.callAjax1(y,(m+1),new Date().getDate());
    return DStr;
};

MyCalendar.prototype.WriteSelect=function(obj,values,action,getobj){
    if(values=="")return;

    if(getobj){
        var YearNO;
		var MonthNO;
        if(action=="y"){
            YearNO = values;
        	MonthNO = MonthTD.innerText.split(" ")[0];
        }

        if(action=="m"){
        	YearNO = YearTD.innerText.split(" ")[0];
        	MonthNO = values;
        }

        obj.innerHTML=values+(action=="y"?" "+this.YEAR:" "+this.MONTH);

        this.RewriteTableStr(YearNO,MonthNO);

	    this.selectedDay(YearNO,(MonthNO-1));
        return false;
    }

    var StrArray=[];
    if(action=="y"){
		var curDate = new Date();
        for(var i=0;i<15;i++){
             var year=curDate.getYear()-14+i;
             StrArray[i]="<option value='"+year+"' "+(values==year?"selected":"")+"> "+year+this.YEAR+"</option>\n";
        }
        obj.innerHTML="<select id='mycalendar_select1' onchange='"+this.objectName+".WriteSelect(parentElement,this.value,\"y\",true)' onblur='YearTD.innerText=this.value+\" "+this.YEAR+"\"'>\n"+StrArray.join("")+"</select>";
        mycalendar_select1.focus();
    }
    if(action=="m"){
        for(var i=1;i<13;i++)
                StrArray[i]="<option value='"+i+"' "+(i==values?"selected":"")+"> "+i+this.MONTH+"</option>\n";
        obj.innerHTML="<select id='mycalendar_select2' style='width:47' onchange='"+this.objectName+".WriteSelect(parentElement,this.value,\"m\",true)' onblur='MonthTD.innerText=this.value+\" "+this.MONTH+"\"'>\n"+StrArray.join("")+"</select>";
        mycalendar_select2.focus();
    }
};

MyCalendar.prototype.RewriteTableStr=function(y,m){
		//alert("rwtable y:" + y + ",m:" + m);
    var TArray=this.GetDataStr(y,(m-1));
   	var cd = document.getElementById("CURCOL");
   //	alert(cd.id);
   	if(cd){
   		//alert(cd.id);
			CURCOL.className="";
			CURCOL.id="TD";
			//alert(cd.id);
		}

    for(var i=0;i<TArray.length;i++){
			TD[i].className="";
			TD[i].innerHTML=TArray[i];
			TD[i].id="TD";


   }
   var curDate = null;
   for(var i=0;i<TArray.length;i++){
	   	var curDay =  new Date();
		if(curDay.getYear()==y&&curDay.getMonth()+1==m&&TArray[i]==curDay.getDate()){

			TD[i].className="calendar_current";
			TD[i].id="CURCOL";
			curDate = curDay.getDate();
		}
   }

   this.callAjax1(y,m,curDate);

};

MyCalendar.prototype.getIndex = function(day){
	if("" == day) return;

	var index = 43;
	for(t=0;t<this.cur_days.length;t++){
		if(day == this.cur_days[t]){
			index = t;
			break;
		}
	}

	return index;
};

MyCalendar.prototype.selectedDay=function(y,m){

	//reset


	var TArray=this.GetDataStr(y,m);


	var cd = document.getElementById("CURCOL");
	//alert(cd.id);
   	if(cd){
   		//alert(cd.id);
			CURCOL.className="";
			CURCOL.id="TD"
			//alert(TD[24] + ":" + TD[26]);
		}

		//reset end




	var days = this.callAjax2(y,m);

	if(days == undefined) return;

	var result = [];
	//alert(days);


	for(i=0;i<days.length;i++){
		if(days[i] != undefined && "" != days[i]){
			for(j=0;j<this.cur_days.length;j++){
				if(TD[j] != undefined){
					var curDay =  new Date();
					if(curDay.getYear()!=y||curDay.getMonth()!=m||days[i]!=curDay.getDate()){
						//alert(days[i] + ":" + this.cur_days[j]);
						if(days[i] == this.cur_days[j]){
							//alert("addResult:" + j);
							result[i] = j;
						}
					}else{
						TD[j].className="";
					}
				}
			}
		}
	}

	for(t=0;t<result.length;t++){
		if(TD[result[t]] != undefined)
			TD[result[t]].className="calendar_msg";
	}

	//set currentdate css
	 var curDate = null;
   for(var i=0;i<TArray.length;i++){
	   	var curDay =  new Date();

		if(curDay.getYear()==y&&curDay.getMonth()==m&&TArray[i]==curDay.getDate()){
			TD[i].className="calendar_current";
			TD[i].id="CURCOL";
		}
	}
		//end


};

MyCalendar.prototype.JumpToRun=function(action){
    var YearNO=YearTD.innerText.split(' ')[0];
    var MonthNO=MonthTD.innerText.split(' ')[0];
    if(action=="b"){
	//alert("b");
        if(MonthNO=="1"){
            MonthNO=13;
            YearNO=YearNO-1;
        }
        MonthTD.innerText=parseInt(MonthNO)-1+" "+this.MONTH;
        YearTD.innerText=parseInt(YearNO)+" "+this.YEAR;
        this.RewriteTableStr(parseInt(YearNO),parseInt(MonthNO)-1);
     		//alert("monthNo:" + MonthNO);
     		this.selectedDay(YearNO,parseInt(MonthNO-2));
    }
    if(action=="n"){
	//alert("n");
        if(MonthNO=="12"){
            MonthNO=0;
            YearNO=YearNO-(-1);
        }
        YearTD.innerText=YearNO+" "+this.YEAR;
        MonthTD.innerText=MonthNO-(-1)+" "+this.MONTH;
        this.RewriteTableStr(YearNO,(MonthNO-(-1)));
				this.selectedDay(YearNO,MonthNO);
    }


};

MyCalendar.prototype.callAjax1 = function(y,m,d){

};

MyCalendar.prototype.callAjax2 = function(y,m){

};

MyCalendar.prototype.callAjax3 = function(y,m,d){

};

MyCalendar.prototype.setTDStyle = function(date,isCancel){
	if(!/\d{4}-{1}\d{1,2}-{1}\d{1,2}$/.test(date)) return;
	var datas = date.split("-");
	var cur_year = YearTD.innerText.split(" ")[0];
	var cur_month = MonthTD.innerText.split(" ")[0];
	if(datas[0] != cur_year || datas[1] != cur_month) return;

	if(datas[2]<1 || datas[2]>31) return;

	var index = this.getIndex(datas[2]);
	var curObj = document.getElementById("CURCOL");
	var curDate = "";
	if(undefined != curObj){
		curDate = curObj.innerText;
		var idx = this.getIndex(curDate);
		if(index >idx) index = index -1;
	}
	if(TD[index] != undefined){
		if(isCancel){
			TD[index].className = "";
		}else{
		   TD[index].className = "calendar_msg";
		}
	}

	if(curDate == "" || " "== curDate){
		curDate = null;
	}
	this.callAjax1(cur_year,cur_month,curDate);
};

/*double click every day */
MyCalendar.prototype.onDbClickFunc = function(obj,y,m,d){
    if(obj.innerText == " ") return false;

    obj.blur();
    this.callAjax3(y,m,d);
};

/*click every day */
MyCalendar.prototype.changeStyle = function(obj,y,m,d){
	  if(obj.innerText == " ") return false;

	  var curObj = document.getElementById("CURCOL");

	  if(curObj != undefined){
		  if(this.isSelected && obj != curObj){
			 curObj.className ="calendar_msg";
			 this.isSelected = false;
		  }else {
		 	curObj.className = "";
		  }

		  curObj.id="TD";
	  }

	  if(obj.className =="calendar_msg"||this.cur_style=="calendar_msg"){
	   	 this.isSelected = true;

	  }

	  obj.id="CURCOL";
	  this.cur_style = "calendar_current"  ; //obj.className;
	  obj.className = "calendar_current";


	 this.callAjax1(y,m,d);
};

MyCalendar.prototype.onMouseOver=function(obj){
	if(obj.innerText == " ") return;
	this.cur_style = obj.className;
	obj.className = "calendar_date_selected";
};

MyCalendar.prototype.onMouseOut=function(obj){
	if(obj.innerText == " ")return;
	obj.className = this.cur_style;
	this.cur_style = "";
};

